package com.bzkj.document.domain;

import com.alibaba.fastjson2.annotation.JSONField;
import com.bzkj.common.core.domain.model.LoginUser;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: prt-wms
 * @package: com.bzkj.document.domain
 * @className: DocConfirmDTO
 * @description: 单据确认DTO
 * @author: C1309
 * @createDate: 2024年12月12日
 * @version: v1.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DocConfirmDTO {

    @JSONField(name = "dbilldate")
    @JsonProperty("dbilldate")
    private String billDate;

    @JSONField(name = "vbillcode")
    @JsonProperty("vbillcode")
    private List<String> vBillCodeList;

    @JSONField(serialize = false)
    private LoginUser loginUser;

    /**
     * 确认类型，0：首次确认，1：二次确认
     */
    @JSONField(serialize = false)
    private Integer confirmType;

    // 自定义反序列化器
    public static class VBillCodeDeserializer extends JsonDeserializer<List<String>> {
        @Override
        public List<String> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
            // 先获取值
            String value = p.getText().trim();

            // 如果是数组格式的 JSON，直接返回
            if (value.startsWith("[") && value.endsWith("]")) {
                // Jackson 会自动把字符串数组转化为 List<String>
                return p.readValueAs(List.class);
            }

            // 如果是单一字符串，将其包装成 List
            List<String> result = new ArrayList<>();
            result.add(value);
            return result;
        }
    }

    public String getBillDate() {
        return billDate;
    }

    public void setBillDate(String billDate) {
        this.billDate = billDate;
    }

    public LoginUser getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(LoginUser loginUser) {
        this.loginUser = loginUser;
    }

    public List<String> getvBillCodeList() {
        return vBillCodeList;
    }

    public void setvBillCodeList(List<String> vBillCodeList) {
        this.vBillCodeList = vBillCodeList;
    }

    public Integer getConfirmType() {
        return confirmType;
    }

    public void setConfirmType(Integer confirmType) {
        this.confirmType = confirmType;
    }

    @Override
    public String toString() {
        return "DocConfirmDTO{" +
                "billDate='" + billDate + '\'' +
                ", vBillCodeList=" + vBillCodeList +
                ", loginUser=" + loginUser +
                ", confirmType=" + confirmType +
                '}';
    }
}
